package com.itheima.test01;

import com.itheima.bean.Card;
import com.itheima.bean.Person;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;
import java.util.List;

public class TestOneToOne {
    @Test
    public void selectAllByPerson() throws Exception{
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        OneToOnePerMapper perMapper = sqlSession.getMapper(OneToOnePerMapper.class);
        List<Card> cardList = perMapper.selectAll();
        for (int i = 0; i < cardList.size(); i++) {
            System.out.println(cardList.get(i));
        }

        sqlSession.close();
        is.close();
    }

    @Test
    public void selectAllByCard() throws Exception{
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        OneToOneNumMapper cardMapper = sqlSession.getMapper(OneToOneNumMapper.class);
        List<Person> personList = cardMapper.selectAll();
        for (int i = 0; i < personList.size(); i++) {
            System.out.println(personList.get(i));
        }
        sqlSession.close();
        is.close();
    }


}
